<?php
if (!defined("BASEPATH")) exit("No direct script access allowed");

class Ent2art extends MY_Model {

	function __construct() {
		parent::__construct();
		$this->tableName = "ent2art";
		$this->prefix = "e2a";
	}

	function getEnt2art($where = NULL) {

		$qs =	"
					select
						e2a_id, e2a_cou_id, e2a_city_id, e2a_ins_id, e2a_maj_id, e2a_art_id
					from
						".$this->db->dbprefix.$this->tableName."
						left join ".$this->db->dbprefix."country on cou_id = e2a_cou_id and cou_del = 0
						left join ".$this->db->dbprefix."city on city_id = e2a_city_id and city_del = 0
						left join ".$this->db->dbprefix."institute on ins_id = e2a_ins_id and ins_del = 0
						left join ".$this->db->dbprefix."major on maj_id = e2a_maj_id and maj_del = 0
					where
						e2a_del = 0".((!is_null($where))?(" and ".$where):(""));
		$result = $this->db->query($qs);
		$getEnt2art = array();
		if($result->num_rows()) {
			foreach ($result->result() as $row) {
				if($row->e2a_cou_id) $getEnt2art[$row->e2a_art_id]["cou"][$row->e2a_id] = $row->e2a_cou_id;
				if($row->e2a_city_id) $getEnt2art[$row->e2a_art_id]["city"][$row->e2a_id] = $row->e2a_city_id;
				if($row->e2a_ins_id) $getEnt2art[$row->e2a_art_id]["ins"][$row->e2a_id] = $row->e2a_ins_id;
				if($row->e2a_maj_id) $getEnt2art[$row->e2a_art_id]["maj"][$row->e2a_id] = $row->e2a_maj_id;
			}
		}

		return $getEnt2art;
	}
	
	function getEnt2artByArtId($artId) {
		$return = array();
		$this->db->select("*");
		$this->db->from($this->tableName);
		$this->db->where($this->prefix."_art_id", $artId);
		$result = $this->db->get();
		if($result->num_rows()) {
			foreach ($result->result() as $row) {
				$return[] = $row;
			}
		}
		return $return;
	}

}